# -*- coding: utf-8 -*-

# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://doc.scrapy.org/en/latest/topics/item-pipeline.html


class ScrapyWwwVultr1ComPipeline(object):
    def process_item(self, item, spider):
        #print(item)
        sql=""
        sql+="INSERT INTO "+item["table"]+" SET "
        item.pop("table")
        for k,v in item.items():
            v=v.replace("\"","'")
            if k=="id" or k=="video_id" or k=="part" or k=="type":
                sql += "`" + k + "`=" + v + ","
            else:
                sql+="`"+k+"`=\""+v+"\","
        sql=sql[:-1]
        #print(sql)
        cursor=spider.db.cursor()
        cursor.execute(sql)
        spider.db.commit()
        return item
